#!/bin/bash

mysql_password=123456
mysql_port=3306
mysql_db=k8s

#安装docker-compose
#wget https://github.com/docker/compose/releases/download/1.24.1/docker-compose-Linux-x86_64
mv docker-compose /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose

#安装mysql
docker pull mysql:8.0.25
docker run -d --name k8s-mysql -p $mysql_port:3306 -v /data/mysql8.0.25:/var/lib/mysql --restart=always  -e MYSQL_ROOT_PASSWORD=$mysql_password -e TZ=Asia/Shanghai mysql:8.0.25 --character-set-server=utf8
sleep 20
docker exec k8s-mysql mysql -uroot -p$mysql_password -P $mysql_port -e "CREATE DATABASE $mysql_db DEFAULT CHARACTER SET utf8;"
sleep 3
#运行服务
docker-compose up -d
sleep 5
#初始化数据
docker cp sql k8s-mysql:/
docker exec k8s-mysql mysql --default-character-set=utf8 -uroot -p$mysql_password -P $mysql_port -e "use $mysql_db;source ./sql/sys_user.sql;"
docker exec k8s-mysql mysql --default-character-set=utf8 -uroot -p$mysql_password -P $mysql_port -e "use $mysql_db;source ./sql/sys_role.sql;"
docker exec k8s-mysql mysql --default-character-set=utf8 -uroot -p$mysql_password -P $mysql_port -e "use $mysql_db;source ./sql/sys_menu.sql;"
docker exec k8s-mysql mysql --default-character-set=utf8 -uroot -p$mysql_password -P $mysql_port -e "use $mysql_db;source ./sql/sys_user_role.sql;"
docker exec k8s-mysql mysql --default-character-set=utf8 -uroot -p$mysql_password -P $mysql_port -e "use $mysql_db;source ./sql/sys_role_menu.sql;"